Merge pull request #1227 from cantino/allow_liquid_in_email_recipients

Allow Liquid in the recipients option

Andrew Cantino 9 years ago
parent
commit
5bcc4f800e
2 changed files with 5 additions and 2 deletions
  1. 1 1
      app/concerns/email_concern.rb
  2. 4 1
      spec/support/shared_examples/email_concern.rb

+ 1 - 1
app/concerns/email_concern.rb

@@ -13,7 +13,7 @@ module EmailConcern
13 13
     if options['recipients'].present?
14 14
       emails = options['recipients']
15 15
       emails = [emails] if emails.is_a?(String)
16
-      unless emails.all? { |email| email =~ Devise.email_regexp }
16
+      unless emails.all? { |email| email =~ Devise.email_regexp || email =~ /\{\{/ }
17 17
         errors.add(:base, "'when provided, 'recipients' should be an email address or an array of email addresses")
18 18
       end
19 19
     end

+ 4 - 1
spec/support/shared_examples/email_concern.rb

@@ -35,7 +35,7 @@ shared_examples_for EmailConcern do
35 35
       expect(agent).not_to be_valid
36 36
     end
37 37
 
38
-    it "should validate that recipients, when provided, is one or more valid email addresses" do
38
+    it "should validate that recipients, when provided, is one or more valid email addresses or Liquid commands" do
39 39
       agent.options['recipients'] = ''
40 40
       expect(agent).to be_valid
41 41
 
@@ -48,6 +48,9 @@ shared_examples_for EmailConcern do
48 48
       agent.options['recipients'] = ['bob@example.com']
49 49
       expect(agent).to be_valid
50 50
 
51
+      agent.options['recipients'] = '{{ email }}'
52
+      expect(agent).to be_valid
53
+
51 54
       agent.options['recipients'] = ['bob@example.com', 'jane@example.com']
52 55
       expect(agent).to be_valid
53 56